<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>原型模式</title>
</head>
<body>
    
</body>
<script>
    //原型模式(Prototype Pattern)
    //用来创建重复的对象，同时保证性能

    //用构造函数创建函数时不能使用箭头函数
    function Person(){
        Person.prototype.name = "Jack"
        Person.prototype.sayName = ()=>{
            console.log(this.name)
        }
    }

    const person1 = new Person()
    const person2 = new Person()
    person1.sayName()
    person2.sayName()
    console.log(person1.sayName == person2.sayName)

</script>
</html>